layui.use(['table', 'util'], function(){
    var table = layui.table,
        util = layui.util;

    var uId = $("#uId").val();

    var paperTable = table.render({
        elem: '#testTable'
        ,url:'/exam/selectExamFinishedPaperByPage'
        ,title: '考试历史数据表'
        ,method: 'get'
        ,where: {uId:uId}
        ,limits: [10,15,20,30]
        ,limit: 10
        ,id:'testTable'
        ,cols: [[
            {field:'id', title:'序号', fixed: 'left',align:'center',type: 'numbers', width: 100, unresize: true, sort: true}
            ,{field:'pname', title:'试卷名',align:'center',fixed: 'left',minWidth: 150}
            ,{field:'uname', title:'姓名',align:'center',fixed: 'left',minWidth: 150}
            ,{field:'upPosttime', title:'交卷时间',align:'center', templet: function (res) {
                    return util.toDateString(res.upPosttime, "yyyy-MM-dd HH:mm:ss");
                }}
            ,{field:'upScore', title:'得分',width: 150,align:'center', templet: function (res) {
                    return res.upScore < (res.pscore * 0.6) ? "<span style='color: red;'>" + res.upScore + "</span>" : res.upScore;
                }}
            ,{field:'pscore', title:'试卷总分',width: 150,align:'center'}
            ,{field:'upStatus', title:'是否评阅',width: 150,align:'center', templet: function (res) {
                    return res.upStatus == "0" ? "<span style='color: red;'>未批阅</span>" : "<span>已批阅</span>";
                }}
            ,{field:'aname', title:'阅卷人',width: 150,align:'center'}
            ,{fixed: 'right', title:'操作',align:'center',width: 150,  toolbar: '#barDemo' }
        ]]
        ,page: true
        ,response: {
            "code": 0,
            "msg": "",
            "count": 1000,
            "data": []
        }
        ,parseData: function(res){ //res 即为原始返回的数据
            return {
                "code": res.data.code, //解析接口状态
                "msg": res.data.msg, //解析提示文本
                "count": res.data.count, //解析数据长度
                "data": res.data.data //解析数据列表
            };
        }

    });


    // 监听行工具事件  将表单提交改为异步
    table.on('tool(test)', function(obj){
        var data = obj.data;
        //跳转试卷详情列表
        if(obj.event === 'paperInfo'){
            window.location.href="/examFinishedInfo/" + data.upId;
        }
    });

});
